package com.syy.example.controller;

import com.syy.example.entity.Blog;
import com.syy.example.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class BlogController {
    @Autowired
    private BlogService blogService;

    @ResponseBody
    @RequestMapping("/getBlog")
    public Blog getBlog(@RequestParam("id") Integer id) {
        return blogService.getById(id);
    }

    @PostMapping("/addBlog")
    public void addBlog(@RequestBody Blog blog) {
        blogService.save(blog);
    }

    @PutMapping("/updateBlog/{id}")
    public boolean updateBlog(@PathVariable Integer id, @RequestBody Blog blog) {
        blog.setId(id);
        return blogService.updateById(blog);
    }

}
